package jgl.vajra.kingkong.part.mine.activity;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.HashMap;
import java.util.Map;

import jgl.vajra.kingkong.R;
import jgl.vajra.kingkong.bean.BankCardBean;
import jgl.vajra.kingkong.databinding.ActivityBankCarBinding;
import jgl.vajra.kingkong.event.BankCardEditEvent;
import jgl.vajra.kingkong.manager.AccountManager;
import jgl.vajra.kingkong.manager.IntentManager;
import jgl.vajra.kingkong.part.mine.contract.BankCardContract;
import jgl.vajra.kingkong.part.mine.viewModel.BankCardViewModel;
import jgl.vajra.kingkong.widget.mvvm.factory.CreateViewModel;
import jgl.vajra.kingkong.widget.mvvm.view.BaseMVVMActivity;
import jgl.vajra.kingkong.widget.utils.UIUtils;

@CreateViewModel(BankCardViewModel.class)
public class BankCardActivity extends BaseMVVMActivity<BankCardViewModel, ActivityBankCarBinding> implements BankCardContract.View {
    @Override
    public int getLayoutId() {
        return R.layout.activity_bank_car;
    }

    @Override
    public void initView() {
        super.initView();
        mBinding.setView(this);

        requestNetData();
    }

    private void requestNetData() {
        Map<String, Object> map = new HashMap<>();
        map.put("Authorization", AccountManager.getInstance().getLoginData(UIUtils.getContext()).authorization);
        map.put("type", 1);//1-银行，2-微信，3-支付宝

        mViewModel.getBankCardData(map);
    }

    //确定
    @Override
    public void onDetermine() {
        IntentManager.toBankCardEditActivity(this);
    }

    @Override
    public void returnBankCardData(BankCardBean data) {
        data.name = "账  户  名：" + data.name;
        data.openBank = "开户银行：" + data.openBank;
        data.openBranch = "开户支行：" + data.openBranch;
        data.openArea = "开户地区：" + data.openArea;
        mBinding.setData(data);
    }

    @Override
    protected boolean isRegisterEvent() {
        return true;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onBankCardEditEvent(BankCardEditEvent event) {
        requestNetData();
    }
}
